<?php

Yii::import('zii.widgets.CPortlet');

class AllCategories extends CPortlet
{
    public function getAllCategories()
    {
        $model = Category::model();
        $categories = $model->localized()->findAll(array ('condition'=>'level=0',));
        
        foreach ($categories as $category) {
            if (count($category->categories)) {
                $category->categories = $model->getCategoriesByParent($category->id);
            }
        }
        
        return $categories;
    }

    protected function renderContent()
    {
        $this->render('allCategories');
    }
}